<%@page contentType="text/html; charset=utf-8"%>

<div class="form-container">
	<form id="form">
		<table class="tableform">
			<tr>
				<th class="td100">菜单名称：</th>
				<td><input name="name" class="easyui-validatebox" type="text" /></td>
			</tr>
			<tr>
				<th class="td100">菜单图标：</th>
				<td><input name="icon" class="easyui-validatebox" type="text" value="viacoin" /></td>
			</tr>
			<tr>
				<th>默认显示：</th>
				<td>
					<div id="icheck">
						<input id="a" type="radio" name="selected" value="false" checked="checked">
						<label class="irl" for="a">否</label>　
						<input id="b" type="radio" name="selected" value="true">
						<label class="irl" for="b">是</label>
					</div>
				</td>
			</tr>
			<tr>
				<th>展示类型：</th>
				<td>
					<div id="icheck">
						<input id="showStyle1" type="radio" name="showStyle" value="tree" checked="checked">
						<label class="irl" for="showStyle1">树状</label>　
						<input id="showStyle2" type="radio" name="showStyle" value="accordion">
						<label class="irl" for="showStyle2">手风琴</label>
					</div>
				</td>
			</tr>
			<tr style="display:none">
				<td>
					<input type="hidden" name="id" value="${id}">
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	var form_url = "${ctx}/admin/sys/menu/add", id = "${id}" ;
	$(function(){
		$('#icheck input').iCheck({
			checkboxClass: 'icheckbox_minimal-blue',
			radioClass: 'iradio_square-blue'
	   	});
		
		if(undefined != id && "" != id) {
			form_url = "${ctx}/admin/sys/menu/update" ;
			$.ajax({
				type: "GET", dataType: "JSON",
				url: "${ctx}/admin/sys/menu/get/"+id,
				success: function(result) {
					$("input[name=showStyle][value="+result.showStyle+"]").iCheck('check') ;
					$("input[name=selected][value="+result.selected+"]").iCheck('check') ;
					$("#form").form("load", result);
				},
				complete: function(XMLHttpRequest, textStatus){},
				error: function(){
					$.easyui.loaded();
					alert("请求出错处理") ;
				}
			});
		}
		
	});
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.message);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.message, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
</script>

